/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.app.meshview.state;

import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import jinngine.math.Quaternion;

/**
 *
 * @author Pierre
 */
class DefaultState extends AbstractState {

    private static final double DISTANCE_SENSIVITY = .85;
    final MeshCamera camera;
    final Quaternion light;

    public DefaultState(MeshCamera camera, Quaternion light) {
        if (camera == null) {
            throw new IllegalArgumentException();
        }
        if (light == null) {
            throw new IllegalArgumentException();
        }
        this.camera = camera;
        this.light = light;
    }

    @Override
    public AbstractState mousePressed(MouseEvent e) {

        if (e.getButton() == MouseEvent.BUTTON1) {
            return new RotateLightState(camera, light, e);
        }

        if (e.getButton() == MouseEvent.BUTTON2) {
            if (e.isControlDown()) {
                return new ZoomState(camera, light, e);
            }
            if (e.isShiftDown()) {
                return new MoveState(camera, light, e);
            }
            return new RotateViewpointState(camera, light, e);
        }
        return this;
    }

    @Override
    public AbstractState mouseWheelMoved(MouseWheelEvent e) {
        if (e.getWheelRotation() > 0) {
            camera.currentDistance /= DISTANCE_SENSIVITY;
        } else {
            camera.currentDistance *= DISTANCE_SENSIVITY;
        }
        redraw(e);
        return this;
    }
}
